import 'package:flutter/material.dart';

import '../../common/system_config.dart';
import '../../utils/tools/screenutil_tool.dart';
import 'concreteicon_widget.dart';

class FixedTopWidget extends StatelessWidget {
  int code;
  List<String> tips = ["网络连接不可用", "WebSocket已断开", "正在重连WebSocket" ];

  FixedTopWidget(int code) {
    //print("接受到的状态$code");
    this.code = code;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      padding: EdgeInsets.symmetric(horizontal: ST.setw(30),vertical: ST.seth(15)),
      color: Color.fromRGBO(255, 237, 237, 1),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          _createWiget(this.code),
          SizedBox(width: ST.setw(20)),
          Text("${tips[code]}",
            style: TextStyle(
              fontSize: ST.setsp(30),
              color: SystemConfig.grayColor
            )
          )
        ],
      ),
    );
  }

  /// ### 创建对应的widget
  /// #### [codetype] int|必填|对应的类型简码
  /// #### 简码说明：0：网络不可用、1：WebSocket异常、2：WebSocket重连
  Widget _createWiget(int codetype) {
    Widget w;
    switch(codetype) {
      case 0 :
        // 网络告警
        w = Icon(Icons.error,color: Colors.red);
        break;
      case 1 :
        // WebSocket告警
        w = Icon(Icons.error,color: Colors.red);
        break;
      case 2 :
        // WebSocket重连
        w = Container(child: CW.circle(size: ST.setsp(50),color: SystemConfig.grayColor));
      break;
    }

    return w;
  }
}